package com.taojin.shoppinginterest.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.widget.ImageView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.taojin.shoppinginterest.R;
import com.taojin.shoppinginterest.utils.AppManager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@ContentView(R.layout.activity_welcome)
public class WelcomeActivity extends ActionBarActivity {
    @ViewInject(R.id.img_welcome)
    private ImageView img;
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            // 跳转界面
            if (msg.what == 0x00) {
                Intent intent = new Intent(WelcomeActivity.this,
                        MainActivity.class);
                startActivity(intent);
                AppManager.getAppManager().finishActivity(WelcomeActivity.class);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewUtils.inject(this);
        AppManager.getAppManager().addActivity(this);
        // 开启线程发消息跳转到主界面
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // executorService.submit(callback) 会有返回值 Future (如果是null,线程正常执行)
        // 可以通过CallBack获取回调方法的内容
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                // 线程的逻辑加入到这里就可以了
                try {
                    Thread.sleep(2000);
                    handler.sendEmptyMessage(0x00);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        // 线程执行完,取消ExecutorService的任务
        executorService.shutdown();
        // 立即取消,并且不接受新的,没有执行的和执行完的全部取消
        // executorService.shutdownNow();
    }


    public RequestParams getRequestParams(){
        RequestParams requestParams = new RequestParams();
        requestParams.addBodyParameter("app", "other");
        requestParams.addBodyParameter("act", "welcome");
        requestParams.addBodyParameter("ver", "1.1");
        requestParams.addBodyParameter("pt", "2");
        return requestParams;
    }
    public void loadBitmap(){

    }
}
